package assist.client.gwt.view.activity;

import assist.client.gwt.service.StatsProvider;
import assist.client.gwt.view.ClientFactory;
import assist.client.gwt.view.event.EditGamesEvent;
import assist.client.gwt.view.place.StatsPlace;
import assist.client.gwt.view.ui.StatsView;
import assist.domain.model.StatsQuery;

public abstract class StatsActivity extends AbstractAssistActivity 
{        
    protected ClientFactory clientFactory;
    protected StatsProvider statsProvider;
    protected StatsQuery statsQuery;
    
    public StatsActivity(StatsPlace place, ClientFactory clientFactory,
            StatsView statsView)
    {        
        //If we're coming from a URL, then Games haven't been set yet.
        if (clientFactory.getGamesProvider().getGamesQuery() == null)
        { 
            clientFactory.getGamesProvider().setGamesQuery(place.getGamesQuery());
        }
        this.clientFactory = clientFactory;
        this.clientFactory.getEventBus().fireEvent(new EditGamesEvent(false));
        this.statsProvider = clientFactory.getStatsProvider();    
        this.statsQuery = place.getStatsQuery();
        //If null, create a new one with team in gamesProvider
        if (this.statsQuery == null)
        {
            this.statsQuery = new StatsQuery(this.clientFactory.getGamesProvider().getGamesQuery().getTeam());
        }        
        this.statsProvider.setStatsQuery(statsQuery);                
    }
    
    public StatsProvider getStatsProvider()
    {
        return this.statsProvider;
    }
}